import { PSDEEditFormItemExImpl } from './control/form/psdeedit-form-item-ex-impl';
import { PSDEFormItemImpl } from './control/form/psdeform-item-impl';
import { IPSModelObject } from './ipsmodel-object';
import { IPSModelService } from './ipsmodel-service';
import { IPSModelServiceProxy } from './ipsmodel-service-proxy';
import {
  PSAppDEFieldServiceProxy,
  PSAppDELogicLinkServiceProxy,
  PSAppDEMethodServiceProxy,
  PSAppDERedirectViewServiceProxy,
  PSAppDERSServiceProxy,
  PSAppDEUILogicNodeServiceProxy,
  PSAppViewLogicServiceProxy,
  PSAppViewMsgServiceProxy,
  PSAppViewServiceProxy,
  PSDEACModeDataItemServiceProxy,
  PSDEACModeServiceProxy,
  PSDEDataExportItemServiceProxy,
  PSDEDataImportItemServiceProxy,
  PSDEDataImportServiceProxy,
  PSDEDRBarItemServiceProxy,
  PSDEFLogicServiceProxy,
  PSDEGridColumnServiceProxy,
  PSDEGridServiceProxy,
  PSDELogicLinkSingleCondServiceProxy,
  PSDELogicNodeParamServiceProxy,
  PSDELogicServiceProxy,
  PSDEUIActionServiceProxy,
  PSDEUILogicLinkServiceProxy,
  PSDEUILogicLinkSingleCondServiceProxy,
  PSDEUILogicNodeParamServiceProxy,
  PSSysDashboardServiceProxy,
} from './proxy-service';
import { PSModelServiceImplBase } from './psmodel-service-impl-base';

/**
 *
 *
 * @export
 * @class PSModelServiceImpl
 * @extends {PSModelServiceImplBase}
 */
export class PSModelServiceImpl extends PSModelServiceImplBase {
  protected createIPSDEFormItem(
    _parentPSModelObject: IPSModelObject,
    _cls: string,
    _objNode: any,
  ): IPSModelObject | null {
    if (_objNode.compositeItem === true) {
      return new PSDEEditFormItemExImpl();
    }
    return new PSDEFormItemImpl();
  }

  /**
   * 根据类型，给模型对象实例化对应的服务代理
   *
   * @protected
   * @param {string} cls
   * @return {*}  {IPSModelService}
   */
  protected getPSModelService(
    cls: string,
    modelObject: IPSModelObject,
  ): IPSModelService {
    if (cls === 'control.IPSControl') {
      if (modelObject.instanceof('control.grid.IPSDEGrid')) {
        return super.getPSModelService('control.grid.IPSDEGrid', modelObject);
      }
    }
    return super.getPSModelService(cls, modelObject);
  }

  protected createPSModelServiceProxy(
    cls: string,
    modelObject: IPSModelObject,
  ): IPSModelServiceProxy {
    if (modelObject) {
      switch (modelObject.cls) {
        case 'PSDEUILogicLinkSingleCondImpl':
          return new PSDEUILogicLinkSingleCondServiceProxy();
        case 'PSDELogicLinkSingleCondImpl':
          return new PSDELogicLinkSingleCondServiceProxy();
        case 'PSAppDEMethodImpl':
          return new PSAppDEMethodServiceProxy();
        case 'PSDEDataImportImpl':
          return new PSDEDataImportServiceProxy();
        case 'PSDEFLogicImpl':
          return new PSDEFLogicServiceProxy();
        case 'PSDEUIActionImpl':
          return new PSDEUIActionServiceProxy();
        case 'PSDEDataExportItemImpl':
          return new PSDEDataExportItemServiceProxy();
        case 'PSAppViewLogicImpl':
        case 'PSAppViewLogicImplBase':
          return new PSAppViewLogicServiceProxy();
        case 'PSSysDashboardImpl':
          return new PSSysDashboardServiceProxy();
        case 'PSAppDERedirectViewImpl':
          return new PSAppDERedirectViewServiceProxy();
        case 'PSDEDataImportItemImpl':
          return new PSDEDataImportItemServiceProxy();
        // case 'PSDEDataViewDataItemImpl':
        //   return new PSDEDataViewDataItemServiceProxy();
        case 'PSDEDRBarItemImpl':
          return new PSDEDRBarItemServiceProxy();
      }
    }
    switch (cls) {
      case 'app.dataentity.IPSAppDELogic':
        return new PSDELogicServiceProxy();
      case 'dataentity.logic.IPSDELogicNodeParam':
      case 'app.dataentity.IPSAppDELogicNodeParam':
        return new PSDELogicNodeParamServiceProxy();
      case 'app.dataentity.IPSAppDERS':
        return new PSAppDERSServiceProxy();
      case 'app.dataentity.IPSAppDEUILogicNode':
        return new PSAppDEUILogicNodeServiceProxy();
      case 'dataentity.logic.IPSDELogicLink':
      case 'app.dataentity.IPSAppDELogicLink':
        return new PSAppDELogicLinkServiceProxy();
      case 'app.view.IPSAppView':
        return new PSAppViewServiceProxy();
      case 'app.view.IPSAppViewMsg':
        return new PSAppViewMsgServiceProxy();
      case 'app.dataentity.IPSAppDEUILogicLink':
      case 'dataentity.logic.IPSDEUILogicLink':
        return new PSDEUILogicLinkServiceProxy();
      case 'app.dataentity.IPSAppDEUILogicNodeParam':
      case 'dataentity.logic.IPSDEUILogicNodeParam':
        return new PSDEUILogicNodeParamServiceProxy();
      case 'control.grid.IPSDEGridEditItem':
        return new PSDEGridColumnServiceProxy();
      case 'control.grid.IPSDEGrid':
        return new PSDEGridServiceProxy();
      case 'app.dataentity.IPSAppDEField':
        return new PSAppDEFieldServiceProxy();
      case 'app.dataentity.IPSAppDEACModeDataItem':
      case 'dataentity.ac.IPSDEACModeDataItem':
        return new PSDEACModeDataItemServiceProxy();
      case 'app.dataentity.IPSAppDEACMode':
      case 'dataentity.ac.IPSDEACMode':
        return new PSDEACModeServiceProxy();
    }
    return null;
  }
}

export const ModelService = new PSModelServiceImpl();
